/*******************************************************************************
 * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
 ******************************************************************************/ 
package demo;

import java.util.List;

import javax.ejb.EJB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cl.gob.ips.offline.jbpm.JBPMBean;
import cl.gob.ips.offline.jbpm.JBPMBeanRemote;
import cl.gob.ips.offline.util.Tarea;

import demo.dao.JBPMDao;

public class FinalizarAperturaAction extends org.apache.struts.action.Action {

	@EJB
    JBPMBeanRemote beanRemote = new JBPMBean(); 
    public FinalizarAperturaAction() {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    	IngresarSolicitudForm formulario = (IngresarSolicitudForm) form;
    	System.out.println("******* "+formulario.getKey());
       //JBPMDao dao = new JBPMDao();
       
    	 //Cerramos apertura e instanciamos tasknode Analisis
        beanRemote.finalizarProcesoActivo(formulario.getKey(), "analisis");
        
        //Seteamos algunas variables a esta tarea, como el tipo de analista que le corresponde
        beanRemote.seteaVariablesTarea(formulario.getKey(),"analisis", "tipo", "revision");
        beanRemote.seteaVariablesTarea(formulario.getKey(),"analisis", "rut", formulario.getRut() + "-" + formulario.getDv());
        beanRemote.seteaVariablesTarea(formulario.getKey(),"analisis", "nombre", formulario.getNombre());
        beanRemote.seteaVariablesTarea(formulario.getKey(),"analisis", "area", formulario.getArea());
        formulario.setTipo(""); 
       
       //JBPMDao dao = new JBPMDao();
      // List<Tarea> tareas = beanRemote.getAssignedTasks("analista","revision");
       //List<Tarea> tareas = dao.traerTareasPorRol("analista",formulario.getTipo());
      
      /*if(tareas.size()==1 && tareas.get(0).getId().equals("0")){
     	 request.setAttribute("vacio", tareas.get(0).getDescripcion());
      }
      request.setAttribute("tareas", tareas);*/
              
       return mapping.findForward("success");
    }
}